package cn.edu.neu.softlab633.influencemaximization.sy.datapreprocessing.InfluenceCal;

import cn.edu.neu.softlab633.influencemaximization.sy.datapreprocessing.ConstantTopic;

import java.util.ArrayList;
import java.util.Map;

/**
 * Created by Jason on 2017/5/8.
 */
public class InfluenceCal {
    public static String calEdgeWeight(long id1, long id2, Map<Long, Double[]> userTopic, Map<Integer, ArrayList<Integer>> idf) {
        StringBuilder influence = new StringBuilder();
        Double[] topic1 = userTopic.get(id1);
        ArrayList<Integer> in = idf.get(id2);
        int size = in.size();
        for (int i = 0; i < topic1.length; i++) {
            double insum = 0;
            for (int j = 0; j < size; j++) {
                insum += userTopic.get(in.get(j))[i];
            }
            double tmp = 1.0 / ConstantTopic.topicNum * (topic1[i] / insum);
            influence.append(tmp + " ");
        }
        return influence.toString();
    }

    public static double calInfluence(Double[] query, Double[] weight) {
        if (query.length != weight.length) {
            System.out.println("影响力传播，输入格式错误");
            System.exit(0);
        }
        double influence = 0.0;
        for (int i = 0; i < query.length; i++) {
            influence += query[i] * weight[i];
        }
        return influence;
    }
}
